package net.onceface.core.domain;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.onceface.core.domain.mappedsuper.TimeIntervalEntity;

import org.hibernate.annotations.Where;

/**
 * 专题类
 * **/
@Entity
@Table(name = "SYS_FEATURE")
public class Feature extends TimeIntervalEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = -7179651500076187261L;

	/**
	 * 名称
	 * **/
	@Column(name = "NAME", nullable = false)
	private String name;

	/**
	 * 是否可用
	 * **/
	@Column(name = "DISABLED")
	private boolean disabled;
	
	@Column(name = "PICTURE")
	private String picture;
	
	/**
	 * 排序
	 * **/
	@Column(name = "SORT_ORDER")
	private Integer sortOrder;

	/**
	 * 开始时间
	 * **/
	@Column(name = "START_TIME", nullable = false)
	@Temporal(TemporalType.DATE)
	private Date startTime;
	
	/**
	 * 首要优惠
	 * **/
	@OneToOne(cascade = {CascadeType.MERGE })
	@JoinColumn(name = "FIRST_DISCOUNT")
	@Where(clause="VALID=1 AND ABOLISH_DATE>NOW()")
	private DisCount firstDiscount;
	
	/**
	 * 次要优惠
	 * **/
	@OneToOne(cascade = {CascadeType.MERGE })
	@JoinColumn(name = "SECOND_DISCOUNT")
	@Where(clause="VALID=1 AND ABOLISH_DATE>NOW()")
	private DisCount secondDiscount;

	/**
	 * 专题商品列表
	 * **/
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name = "SYS_PRODUCT_RELATION",
			joinColumns = @JoinColumn(name = "FEATURE_ID"),
			inverseJoinColumns = @JoinColumn(name = "PRODUCT_ID"))
	private Set<Product> products;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isDisabled() {
		return disabled;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

	public String getPicture() {
		return picture;
	}

	public void setPicture(String picture) {
		this.picture = picture;
	}

	public DisCount getFirstDiscount() {
		return firstDiscount;
	}

	public void setFirstDiscount(DisCount firstDiscount) {
		this.firstDiscount = firstDiscount;
	}

	public DisCount getSecondDiscount() {
		return secondDiscount;
	}

	public void setSecondDiscount(DisCount secondDiscount) {
		this.secondDiscount = secondDiscount;
	}

	public Integer getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(Integer sortOrder) {
		this.sortOrder = sortOrder;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Set<Product> getProducts() {
		return products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}
	@Override
	public String[] businessKeys() {
		// TODO Auto-generated method stub
		return null;
	}

}
